import modelEntity from "./modelEntity";
export default class ProgressConstruction extends modelEntity {
  constructor(options) {
    super(options);
    this.Time = options.Time;
    this.Pos = options.Pos;
    this.Progress = options.Progress;
    this.ProgressSimple = ((this.Progress)&&(this.Progress.length > 10)) ? this.Progress.substring(0, 10) + ".." : this.Progress;
    this.basePath = "工程进度";
    this.fileResult = [];
  }
  static newInstance() {
    return new ProgressConstruction({
      Time: "",
      Pos: "",
      Progress: "",
      basePath: "工程进度",
      fileResult: []
    })
  }
  static loadList() {
    return new Promise((resolve, reject) => {
      getApp().globalData.api.http_get(`${getApp().globalData.baseUrl}/api/prj/progressconstruction?prj=${getApp().globalData.nowPrj.GuidID}`)
        .then(
          res => {
            console.log(res);
            let list = [];
            res.forEach(x => {
              list.push(new ProgressConstruction(x));
            });
            resolve(list);
          }
        )
    })
  }
  create() {
    return new Promise((resolve, reject) => {
      getApp().globalData.api.http_post_json(`${getApp().globalData.baseUrl}/api/prj/progressconstruction?prj=${getApp().globalData.nowPrj.GuidID}`,this)
        .then(
          res => {
            let model = new ProgressConstruction(res);
            resolve(model);
          }
        )
    })
  }
  delete() {
    return new Promise((resolve, reject) => {
      window.api.http_delete("/api/prj/progressconstruction?prj=" + window.nowPrj.pCode, this)
        .then(
          res => {
            resolve(res);
          }
        )
    })
  }
  modify() {
    return new Promise((resolve, reject) => {
      window.api.http_put("/api/prj/progressconstruction?prj=" + window.nowPrj.pCode, this)
        .then(
          res => {
            let model = new ProgressConstruction(res);
            resolve(model);
          }
        )
    })
  }
}
